package com.dailyblue.javaee.controller;

import com.dailyblue.javaee.bean.Emp;
import com.dailyblue.javaee.service.EmpService;
import com.dailyblue.javaee.service.impl.EmpServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

@WebServlet("/emp_find")
public class EmpFindController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1. 产生service的对象
        EmpService service = new EmpServiceImpl();
        // 2. 调用方法获取到list
        List<Emp> list = service.find();
        // 3. 获取session并存放到容器中
        HttpSession session = request.getSession();
        session.setAttribute("LIST",list);
        // 4. 重定向的显示页面
        response.sendRedirect("emp.jsp");
    }
}